<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%@ page import="awesome.Manager.UserManager" %>
<%@ page import="awesome.mail.MailInterface" %>
<%
String username = request.getParameter("username");
String password1 = request.getParameter("password1");
String password2 = request.getParameter("password2");
String country = request.getParameter("country");

String first_name = request.getParameter("first_name");
String mi = request.getParameter("MI");
String last_name = request.getParameter("last_name");

String email = request.getParameter("email");
String phone = request.getParameter("phone");

String address = request.getParameter("address");
String city = request.getParameter("city");
String state = request.getParameter("state");
String zipcode = request.getParameter("zipcode");



if(!password1.equals(password2))
	{
	RequestDispatcher rd = request.getRequestDispatcher("signup.jsp?error=1");
	rd.forward(request,response);
	}

	UserManager um = new UserManager();
	
	if(um.checkUsername(username) == false)
	{
		RequestDispatcher rd = request.getRequestDispatcher("signup.jsp?error=2");
		rd.forward(request,response);
	}
	
	
	um.insertRow(username, first_name, mi, last_name,password1,
			email, address, country,
			city, state, zipcode, phone);
	
	String validationID= um.getIdentification(username,password1);
	
	String link = "http://localhost:8080/AwesomeAuctions/validate.jsp?username="+username+"&validationID="+validationID;

	String message  = "<font type=\"verdana\" size=\"2\" >" +
	"Dear "+ first_name+", " +
	"<br /><br />&nbsp;&nbsp;&nbsp;&nbsp; "
	+"Thank you for choosing Awesome Auctions."
	+"Please click at the following link to validate your account."
	+"<br /><br /><a href=\""+ link +"\"> Click here to Validate </a>"+
	"<br /><br />Thank you " +
	"!<br /><br />Awesome Auctions " +
	"<br />" +
	"</font>";
	
	MailInterface.sendEmail(email, message);
%>
	
<%@include file='templates/header.jsp'%>
	<br /><h2>Registration Complete</h2>
	Thank you for choosing Awesome Auction.
	Please check your email to validate your account. <br /><br />
	
	<a href ="validate.jsp?username=<%=username %>&validationID=<%=validationID %>">Click Here</a>
<%@include file='templates/footer.jsp'%>